home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / cnews.orig.lzh / libc / getdate.tab.c < prev    next >
C/C++ Source or Header  |  1989-06-28  |  28KB  |  1,154 lines

  1. # define ID 257
  2. # define MONTH 258
  3. # define DAY 259
  4. # define MERIDIAN 260
  5. # define NUMBER 261
  6. # define UNIT 262
  7. # define MUNIT 263
  8. # define SUNIT 264
  9. # define ZONE 265
  10. # define DAYZONE 266
  11. # define AGO 267
  12.  
  13. # line 3 "getdate.y"
  14.     /*     Steven M. Bellovin (unc!smb)            */
  15.     /*    Dept. of Computer Science            */
  16.     /*    University of North Carolina at Chapel Hill    */
  17.     /*    @(#)getdate.y    2.13    9/16/86 */
  18.  
  19. #include <sys/types.h>
  20. #include <sys/timeb.h>
  21. #include <ctype.h>
  22. #include <time.h>
  23.  
  24. #define    NULL    0
  25.  
  26. #define daysec (24L*60L*60L)
  27.  
  28.     static int timeflag, zoneflag, dateflag, dayflag, relflag;
  29.     static time_t relsec, relmonth;
  30.     static int hh, mm, ss, merid, daylight;
  31.     static int dayord, dayreq;
  32.     static int month, day, year;
  33.     static int ourzone;
  34.  
  35. #define AM 1
  36. #define PM 2
  37. #define DAYLIGHT 1
  38. #define STANDARD 2
  39. #define MAYBE    3
  40. #define yyclearin yychar = -1
  41. #define yyerrok yyerrflag = 0
  42. extern int yychar;
  43. extern int yyerrflag;
  44. #ifndef YYMAXDEPTH
  45. #define YYMAXDEPTH 150
  46. #endif
  47. #ifndef YYSTYPE
  48. #define YYSTYPE int
  49. #endif
  50. YYSTYPE yylval, yyval;
  51. typedef int yytabelem;
  52. # define YYERRCODE 256
  53.  
  54. # line 108 "getdate.y"
  55.  
  56.  
  57. static int mdays[12] =
  58.     {31, 0, 31,  30, 31, 30,  31, 31, 30,  31, 30, 31};
  59. #define epoch 1970
  60.  
  61. extern struct tm *localtime();
  62. time_t dateconv(mm, dd, yy, h, m, s, mer, zone, dayflag)
  63. int mm, dd, yy, h, m, s, mer, zone, dayflag;
  64. {
  65.     time_t tod, jdate;
  66.     register int i;
  67.     time_t timeconv();
  68.  
  69.     if (yy < 0) yy = -yy;
  70.     if (yy < 100) yy += 1900;
  71.     mdays[1] = 28 + (yy%4 == 0 && (yy%100 != 0 || yy%400 == 0));
  72.     if (yy < epoch || yy > 1999 || mm < 1 || mm > 12 ||
  73.         dd < 1 || dd > mdays[--mm]) return (-1);
  74.     jdate = dd-1;
  75.         for (i=0; i<mm; i++) jdate += mdays[i];
  76.     for (i = epoch; i < yy; i++) jdate += 365 + (i%4 == 0);
  77.     jdate *= daysec;
  78.     jdate += zone * 60L;
  79.     if ((tod = timeconv(h, m, s, mer)) < 0) return (-1);
  80.     jdate += tod;
  81.     if (dayflag==DAYLIGHT || (dayflag==MAYBE&&localtime(&jdate)->tm_isdst))
  82.         jdate += -1*60*60;
  83.     return (jdate);
  84. }
  85.  
  86. time_t dayconv(ord, day, now) int ord, day; time_t now;
  87. {
  88.     register struct tm *loctime;
  89.     time_t tod;
  90.     time_t daylcorr();
  91.  
  92.     tod = now;
  93.     loctime = localtime(&tod);
  94.     tod += daysec * ((day - loctime->tm_wday + 7) % 7);
  95.     tod += 7*daysec*(ord<=0?ord:ord-1);
  96.     return daylcorr(tod, now);
  97. }
  98.  
  99. time_t timeconv(hh, mm, ss, mer) register int hh, mm, ss, mer;
  100. {
  101.     if (mm < 0 || mm > 59 || ss < 0 || ss > 59) return (-1);
  102.     switch (mer) {
  103.         case AM: if (hh < 1 || hh > 12) return(-1);
  104.              return (60L * ((hh%12)*60L + mm)+ss);
  105.         case PM: if (hh < 1 || hh > 12) return(-1);
  106.              return (60L * ((hh%12 +12)*60L + mm)+ss);
  107.         case 24: if (hh < 0 || hh > 23) return (-1);
  108.              return (60L * (hh*60L + mm)+ss);
  109.         default: return (-1);
  110.     }
  111. }
  112. time_t monthadd(sdate, relmonth) time_t sdate, relmonth;
  113. {
  114.     struct tm *ltime;
  115.     time_t dateconv();
  116.     time_t daylcorr();
  117.     int mm, yy;
  118.  
  119.     if (relmonth == 0) return 0;
  120.     ltime = localtime(&sdate);
  121.     mm = 12*ltime->tm_year + ltime->tm_mon + relmonth;
  122.     yy = mm/12;
  123.     mm = mm%12 + 1;
  124.     return daylcorr(dateconv(mm, ltime->tm_mday, yy, ltime->tm_hour,
  125.         ltime->tm_min, ltime->tm_sec, 24, ourzone, MAYBE), sdate);
  126. }
  127.  
  128. time_t daylcorr(future, now) time_t future, now;
  129. {
  130.     int fdayl, nowdayl;
  131.  
  132.     nowdayl = (localtime(&now)->tm_hour+1) % 24;
  133.     fdayl = (localtime(&future)->tm_hour+1) % 24;
  134.     return (future-now) + 60L*60L*(nowdayl-fdayl);
  135. }
  136.  
  137. static char *lptr;
  138.  
  139. yylex()
  140. {
  141.     extern int yylval;
  142.     int sign;
  143.     register char c;
  144.     register char *p;
  145.     char idbuf[20];
  146.     int pcnt;
  147.  
  148.     for (;;) {
  149.         while (isspace(*lptr)) lptr++;
  150.  
  151.         if (isdigit(c = *lptr) || c == '-' || c == '+') {
  152.             if (c== '-' || c == '+') {
  153.                 if (c=='-') sign = -1;
  154.                 else sign = 1;
  155.                 if (!isdigit(*++lptr)) {
  156.                     /* yylval = sign; return (NUMBER); */
  157.                     return yylex();    /* skip the '-' sign */
  158.                 }
  159.             } else sign = 1;
  160.             yylval = 0;
  161.             while (isdigit(c = *lptr++)) yylval = 10*yylval + c - '0';
  162.             yylval *= sign;
  163.             lptr--;
  164.             return (NUMBER);
  165.  
  166.         } else if (isalpha(c)) {
  167.             p = idbuf;
  168.             while (isalpha(c = *lptr++) || c=='.')
  169.                 if (p < &idbuf[sizeof(idbuf)-1])
  170.                     *p++ = c;
  171.             *p = '\0';
  172.             lptr--;
  173.             return (lookup(idbuf));
  174.         }
  175.  
  176.         else if (c == '(') {
  177.             pcnt = 0;
  178.             do {
  179.                 c = *lptr++;
  180.                 if (c == '\0') return(c);
  181.                 else if (c == '(') pcnt++;
  182.                 else if (c == ')') pcnt--;
  183.             } while (pcnt > 0);
  184.         }
  185.  
  186.         else return (*lptr++);
  187.     }
  188. }
  189.  
  190. struct table {
  191.     char *name;
  192.     int type, value;
  193. };
  194.  
  195. struct table mdtab[] = {
  196.     {"January", MONTH, 1},
  197.     {"February", MONTH, 2},
  198.     {"March", MONTH, 3},
  199.     {"April", MONTH, 4},
  200.     {"May", MONTH, 5},
  201.     {"June", MONTH, 6},
  202.     {"July", MONTH, 7},
  203.     {"August", MONTH, 8},
  204.     {"September", MONTH, 9},
  205.     {"Sept", MONTH, 9},
  206.     {"October", MONTH, 10},
  207.     {"November", MONTH, 11},
  208.     {"December", MONTH, 12},
  209.  
  210.     {"Sunday", DAY, 0},
  211.     {"Monday", DAY, 1},
  212.     {"Tuesday", DAY, 2},
  213.     {"Tues", DAY, 2},
  214.     {"Wednesday", DAY, 3},
  215.     {"Wednes", DAY, 3},
  216.     {"Thursday", DAY, 4},
  217.     {"Thur", DAY, 4},
  218.     {"Thurs", DAY, 4},
  219.     {"Friday", DAY, 5},
  220.     {"Saturday", DAY, 6},
  221.     {0, 0, 0}};
  222.  
  223. #define HRS *60
  224. #define HALFHR 30
  225. struct table mztab[] = {
  226.     {"a.m.", MERIDIAN, AM},
  227.     {"am", MERIDIAN, AM},
  228.     {"p.m.", MERIDIAN, PM},
  229.     {"pm", MERIDIAN, PM},
  230.     {"nst", ZONE, 3 HRS + HALFHR},        /* Newfoundland */
  231.     {"n.s.t.", ZONE, 3 HRS + HALFHR},
  232.     {"ast", ZONE, 4 HRS},        /* Atlantic */
  233.     {"a.s.t.", ZONE, 4 HRS},
  234.     {"adt", DAYZONE, 4 HRS},
  235.     {"a.d.t.", DAYZONE, 4 HRS},
  236.     {"est", ZONE, 5 HRS},        /* Eastern */
  237.     {"e.s.t.", ZONE, 5 HRS},
  238.     {"edt", DAYZONE, 5 HRS},
  239.     {"e.d.t.", DAYZONE, 5 HRS},
  240.     {"cst", ZONE, 6 HRS},        /* Central */
  241.     {"c.s.t.", ZONE, 6 HRS},
  242.     {"cdt", DAYZONE, 6 HRS},
  243.     {"c.d.t.", DAYZONE, 6 HRS},
  244.     {"mst", ZONE, 7 HRS},        /* Mountain */
  245.     {"m.s.t.", ZONE, 7 HRS},
  246.     {"mdt", DAYZONE, 7 HRS},
  247.     {"m.d.t.", DAYZONE, 7 HRS},
  248.     {"pst", ZONE, 8 HRS},        /* Pacific */
  249.     {"p.s.t.", ZONE, 8 HRS},
  250.     {"pdt", DAYZONE, 8 HRS},
  251.     {"p.d.t.", DAYZONE, 8 HRS},
  252.     {"yst", ZONE, 9 HRS},        /* Yukon */
  253.     {"y.s.t.", ZONE, 9 HRS},
  254.     {"ydt", DAYZONE, 9 HRS},
  255.     {"y.d.t.", DAYZONE, 9 HRS},
  256.     {"hst", ZONE, 10 HRS},        /* Hawaii */
  257.     {"h.s.t.", ZONE, 10 HRS},
  258.     {"hdt", DAYZONE, 10 HRS},
  259.     {"h.d.t.", DAYZONE, 10 HRS},
  260.  
  261.     {"gmt", ZONE, 0 HRS},
  262.     {"g.m.t.", ZONE, 0 HRS},
  263.     {"bst", DAYZONE, 0 HRS},        /* British Summer Time */
  264.     {"b.s.t.", DAYZONE, 0 HRS},
  265.     {"eet", ZONE, 0 HRS},        /* European Eastern Time */
  266.     {"e.e.t.", ZONE, 0 HRS},
  267.     {"eest", DAYZONE, 0 HRS},    /* European Eastern Summer Time */
  268.     {"e.e.s.t.", DAYZONE, 0 HRS},
  269.     {"met", ZONE, -1 HRS},        /* Middle European Time */
  270.     {"m.e.t.", ZONE, -1 HRS},
  271.     {"mest", DAYZONE, -1 HRS},    /* Middle European Summer Time */
  272.     {"m.e.s.t.", DAYZONE, -1 HRS},
  273.     {"wet", ZONE, -2 HRS },        /* Western European Time */
  274.     {"w.e.t.", ZONE, -2 HRS },
  275.     {"west", DAYZONE, -2 HRS},    /* Western European Summer Time */
  276.     {"w.e.s.t.", DAYZONE, -2 HRS},
  277.  
  278.     {"jst", ZONE, -9 HRS},        /* Japan Standard Time */
  279.     {"j.s.t.", ZONE, -9 HRS},    /* Japan Standard Time */
  280.                     /* No daylight savings time */
  281.  
  282.     {"aest", ZONE, -10 HRS},    /* Australian Eastern Time */
  283.     {"a.e.s.t.", ZONE, -10 HRS},
  284.     {"aesst", DAYZONE, -10 HRS},    /* Australian Eastern Summer Time */
  285.     {"a.e.s.s.t.", DAYZONE, -10 HRS},
  286.     {"acst", ZONE, -(9 HRS + HALFHR)},    /* Australian Central Time */
  287.     {"a.c.s.t.", ZONE, -(9 HRS + HALFHR)},
  288.     {"acsst", DAYZONE, -(9 HRS + HALFHR)},    /* Australian Central Summer */
  289.     {"a.c.s.s.t.", DAYZONE, -(9 HRS + HALFHR)},
  290.     {"awst", ZONE, -8 HRS},        /* Australian Western Time */
  291.     {"a.w.s.t.", ZONE, -8 HRS},    /* (no daylight time there, I'm told */
  292.     {0, 0, 0}};
  293.  
  294. struct table unittb[] = {
  295.     {"year", MUNIT, 12},
  296.     {"month", MUNIT, 1},
  297.     {"fortnight", UNIT, 14*24*60},
  298.     {"week", UNIT, 7*24*60},
  299.     {"day", UNIT, 1*24*60},
  300.     {"hour", UNIT, 60},
  301.     {"minute", UNIT, 1},
  302.     {"min", UNIT, 1},
  303.     {"second", SUNIT, 1},
  304.     {"sec", SUNIT, 1},
  305.     {0, 0, 0}};
  306.  
  307. struct table othertb[] = {
  308.     {"tomorrow", UNIT, 1*24*60},
  309.     {"yesterday", UNIT, -1*24*60},
  310.     {"today", UNIT, 0},
  311.     {"now", UNIT, 0},
  312.     {"last", NUMBER, -1},
  313.     {"this", UNIT, 0},
  314.     {"next", NUMBER, 2},
  315.     {"first", NUMBER, 1},
  316.     /* {"second", NUMBER, 2}, */
  317.     {"third", NUMBER, 3},
  318.     {"fourth", NUMBER, 4},
  319.     {"fifth", NUMBER, 5},
  320.     {"sixth", NUMBER, 6},
  321.     {"seventh", NUMBER, 7},
  322.     {"eigth", NUMBER, 8},
  323.     {"ninth", NUMBER, 9},
  324.     {"tenth", NUMBER, 10},
  325.     {"eleventh", NUMBER, 11},
  326.     {"twelfth", NUMBER, 12},
  327.     {"ago", AGO, 1},
  328.     {0, 0, 0}};
  329.  
  330. struct table milzone[] = {
  331.     {"a", ZONE, 1 HRS},
  332.     {"b", ZONE, 2 HRS},
  333.     {"c", ZONE, 3 HRS},
  334.     {"d", ZONE, 4 HRS},
  335.     {"e", ZONE, 5 HRS},
  336.     {"f", ZONE, 6 HRS},
  337.     {"g", ZONE, 7 HRS},
  338.     {"h", ZONE, 8 HRS},
  339.     {"i", ZONE, 9 HRS},
  340.     {"k", ZONE, 10 HRS},
  341.     {"l", ZONE, 11 HRS},
  342.     {"m", ZONE, 12 HRS},
  343.     {"n", ZONE, -1 HRS},
  344.     {"o", ZONE, -2 HRS},
  345.     {"p", ZONE, -3 HRS},
  346.     {"q", ZONE, -4 HRS},
  347.     {"r", ZONE, -5 HRS},
  348.     {"s", ZONE, -6 HRS},
  349.     {"t", ZONE, -7 HRS},
  350.     {"u", ZONE, -8 HRS},
  351.     {"v", ZONE, -9 HRS},
  352.     {"w", ZONE, -10 HRS},
  353.     {"x", ZONE, -11 HRS},
  354.     {"y", ZONE, -12 HRS},
  355.     {"z", ZONE, 0 HRS},
  356.     {0, 0, 0}};
  357.  
  358. lookup(id) char *id;
  359. {
  360. #define gotit (yylval=i->value,  i->type)
  361. #define getid for(j=idvar, k=id; *j++ = *k++; )
  362.  
  363.     char idvar[20];
  364.     register char *j, *k;
  365.     register struct table *i;
  366.     int abbrev;
  367.  
  368.     getid;
  369.     if (strlen(idvar) == 3) abbrev = 1;
  370.     else if (strlen(idvar) == 4 && idvar[3] == '.') {
  371.         abbrev = 1;
  372.         idvar[3] = '\0';
  373.     }
  374.     else abbrev = 0;
  375.  
  376.     if (islower(*idvar)) *idvar = toupper(*idvar);
  377.  
  378.     for (i = mdtab; i->name; i++) {
  379.         k = idvar;
  380.         for (j = i->name; *j++ == *k++;) {
  381.             if (abbrev && j==i->name+3) return gotit;
  382.             if (j[-1] == 0) return gotit;
  383.         }
  384.     }
  385.  
  386.     getid;
  387.     for (i = mztab; i->name; i++)
  388.         if (strcmp(i->name, idvar) == 0) return gotit;
  389.  
  390.     for (j = idvar; *j; j++)
  391.         if (isupper(*j)) *j = tolower(*j);
  392.     for (i=mztab; i->name; i++)
  393.         if (strcmp(i->name, idvar) == 0) return gotit;
  394.  
  395.     getid;
  396.     for (i=unittb; i->name; i++)
  397.         if (strcmp(i->name, idvar) == 0) return gotit;
  398.  
  399.     if (idvar[strlen(idvar)-1] == 's')
  400.         idvar[strlen(idvar)-1] = '\0';
  401.     for (i=unittb; i->name; i++)
  402.         if (strcmp(i->name, idvar) == 0) return gotit;
  403.  
  404.     getid;
  405.     for (i = othertb; i->name; i++)
  406.         if (strcmp(i->name, idvar) == 0) return gotit;
  407.  
  408.     getid;
  409.     if (strlen(idvar) == 1 && isalpha(*idvar)) {
  410.         if (isupper(*idvar)) *idvar = tolower(*idvar);
  411.         for (i = milzone; i->name; i++)
  412.             if (strcmp(i->name, idvar) == 0) return gotit;
  413.     }
  414.  
  415.     return(ID);
  416. }
  417.  
  418. time_t getdate(p, now) char *p; struct timeb *now;
  419. {
  420. #define mcheck(f)    if (f>1) err++
  421.     time_t monthadd();
  422.     int err;
  423.     struct tm *lt;
  424.     struct timeb ftz;
  425.  
  426.     time_t sdate, tod;
  427.  
  428.     lptr = p;
  429.     if (now == ((struct timeb *) NULL)) {
  430.         now = &ftz;
  431.         ftime(&ftz);
  432.     }
  433.     lt = localtime(&now->time);
  434.     year = lt->tm_year;
  435.     month = lt->tm_mon+1;
  436.     day = lt->tm_mday;
  437.     relsec = 0; relmonth = 0;
  438.     timeflag=zoneflag=dateflag=dayflag=relflag=0;
  439.     ourzone = now->timezone;
  440.     daylight = MAYBE;
  441.     hh = mm = ss = 0;
  442.     merid = 24;
  443.  
  444.     if (err = yyparse()) return (-1);
  445.  
  446.     mcheck(timeflag);
  447.     mcheck(zoneflag);
  448.     mcheck(dateflag);
  449.     mcheck(dayflag);
  450.  
  451.     if (err) return (-1);
  452.     if (dateflag || timeflag || dayflag) {
  453.         sdate = dateconv(month,day,year,hh,mm,ss,merid,ourzone,daylight);
  454.         if (sdate < 0) return -1;
  455.     }
  456.     else {
  457.         sdate = now->time;
  458.         if (relflag == 0)
  459.             sdate -= (lt->tm_sec + lt->tm_min*60 +
  460.                 lt->tm_hour*(60L*60L));
  461.     }
  462.  
  463.     sdate += relsec;
  464.     sdate += monthadd(sdate, relmonth);
  465.  
  466.     if (dayflag && !dateflag) {
  467.         tod = dayconv(dayord, dayreq, sdate);
  468.         sdate += tod;
  469.     }
  470.  
  471.     return sdate;
  472. }
  473.  
  474. yyerror(s) char *s;
  475. {}
  476. yytabelem yyexca[] ={
  477. -1, 1,
  478.     0, -1,
  479.     -2, 0,
  480.     };
  481. # define YYNPROD 35
  482. # define YYLAST 220
  483. yytabelem yyact[]={
  484.  
  485.     12,    13,    21,     9,    14,    15,    16,    10,    11,    34,
  486.     17,    39,    40,    19,    38,    37,    36,    30,    29,    28,
  487.     26,    35,    31,    27,     8,     7,     6,     5,     4,     3,
  488.      2,     1,     0,     0,     0,     0,     0,     0,     0,     0,
  489.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  490.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  491.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  492.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  493.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  494.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  495.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  496.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  497.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  498.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  499.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  500.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  501.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  502.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  503.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  504.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  505.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  506.      0,    32,    33,    22,    20,    18,     0,    23,    24,    25 };
  507. yytabelem yypact[]={
  508.  
  509.  -1000,  -258, -1000, -1000, -1000, -1000, -1000,  -257, -1000,   -45,
  510.  -1000, -1000,  -241,   -21, -1000, -1000, -1000, -1000, -1000,  -242,
  511.  -1000,  -243,  -244, -1000, -1000, -1000,   -22, -1000,   -49,   -26,
  512.  -1000,  -245, -1000, -1000,  -246,  -247, -1000,  -249, -1000, -1000,
  513.  -1000 };
  514. yytabelem yypgo[]={
  515.  
  516.      0,    31,    30,    29,    28,    27,    26,    25,    24 };
  517. yytabelem yyr1[]={
  518.  
  519.      0,     1,     1,     2,     2,     2,     2,     2,     2,     8,
  520.      3,     3,     3,     3,     3,     3,     3,     4,     4,     6,
  521.      6,     6,     5,     5,     5,     5,     5,     5,     7,     7,
  522.      7,     7,     7,     7,     7 };
  523. yytabelem yyr2[]={
  524.  
  525.      0,     0,     4,     3,     3,     3,     3,     3,     2,     3,
  526.      5,     7,     9,     9,    11,    13,    13,     3,     3,     3,
  527.      5,     5,     7,    11,     5,     9,     5,     7,     5,     5,
  528.      5,     3,     3,     3,     5 };
  529. yytabelem yychk[]={
  530.  
  531.  -1000,    -1,    -2,    -3,    -4,    -5,    -6,    -7,    -8,   261,
  532.    265,   266,   258,   259,   262,   263,   264,   267,   260,    58,
  533.    259,    47,   258,   262,   263,   264,   261,    44,   261,   261,
  534.    261,    44,   260,   261,    58,    47,   261,   261,   261,   260,
  535.    261 };
  536. yytabelem yydef[]={
  537.  
  538.      1,    -2,     2,     3,     4,     5,     6,     7,     8,     9,
  539.     17,    18,     0,    19,    31,    32,    33,    34,    10,     0,
  540.     21,     0,    26,    28,    29,    30,    24,    20,    11,    22,
  541.     27,     0,    12,    13,     0,     0,    25,    14,    23,    15,
  542.     16 };
  543. typedef struct { char *t_name; int t_val; } yytoktype;
  544. #ifndef YYDEBUG
  545. #    define YYDEBUG    0    /* don't allow debugging */
  546. #endif
  547.  
  548. #if YYDEBUG
  549.  
  550. yytoktype yytoks[] =
  551. {
  552.     "ID",    257,
  553.     "MONTH",    258,
  554.     "DAY",    259,
  555.     "MERIDIAN",    260,
  556.     "NUMBER",    261,
  557.     "UNIT",    262,
  558.     "MUNIT",    263,
  559.     "SUNIT",    264,
  560.     "ZONE",    265,
  561.     "DAYZONE",    266,
  562.     "AGO",    267,
  563.     "-unknown-",    -1    /* ends search */
  564. };
  565.  
  566. char * yyreds[] =
  567. {
  568.     "-no such reduction-",
  569.     "timedate : /* empty */",
  570.     "timedate : timedate item",
  571.     "item : tspec",
  572.     "item : zone",
  573.     "item : dtspec",
  574.     "item : dyspec",
  575.     "item : rspec",
  576.     "item : nspec",
  577.     "nspec : NUMBER",
  578.     "tspec : NUMBER MERIDIAN",
  579.     "tspec : NUMBER ':' NUMBER",
  580.     "tspec : NUMBER ':' NUMBER MERIDIAN",
  581.     "tspec : NUMBER ':' NUMBER NUMBER",
  582.     "tspec : NUMBER ':' NUMBER ':' NUMBER",
  583.     "tspec : NUMBER ':' NUMBER ':' NUMBER MERIDIAN",
  584.     "tspec : NUMBER ':' NUMBER ':' NUMBER NUMBER",
  585.     "zone : ZONE",
  586.     "zone : DAYZONE",
  587.     "dyspec : DAY",
  588.     "dyspec : DAY ','",
  589.     "dyspec : NUMBER DAY",
  590.     "dtspec : NUMBER '/' NUMBER",
  591.     "dtspec : NUMBER '/' NUMBER '/' NUMBER",
  592.     "dtspec : MONTH NUMBER",
  593.     "dtspec : MONTH NUMBER ',' NUMBER",
  594.     "dtspec : NUMBER MONTH",
  595.     "dtspec : NUMBER MONTH NUMBER",
  596.     "rspec : NUMBER UNIT",
  597.     "rspec : NUMBER MUNIT",
  598.     "rspec : NUMBER SUNIT",
  599.     "rspec : UNIT",
  600.     "rspec : MUNIT",
  601.     "rspec : SUNIT",
  602.     "rspec : rspec AGO",
  603. };
  604. #endif /* YYDEBUG */
  605. /*    @(#) yaccpar.src 1.2 88/10/25 
  606.  *
  607.  *    Copyright (C) The Santa Cruz Operation, 1985.
  608.  *    This Module contains Proprietary Information of
  609.  *    The Santa Cruz Operation, Microsoft Corporation
  610.  *    and AT&T, and should be treated as Confidential.
  611.  */
  612.  
  613. /*
  614. ** Skeleton parser driver for yacc output
  615. */
  616.  
  617. /*
  618. ** yacc user known macros and defines
  619. */
  620. #define YYERROR        goto yyerrlab
  621. #define YYACCEPT    return(0)
  622. #define YYABORT        return(1)
  623. #define YYBACKUP( newtoken, newvalue )\
  624. {\
  625.     if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\
  626.     {\
  627.         yyerror( "syntax error - cannot backup" );\
  628.         goto yyerrlab;\
  629.     }\
  630.     yychar = newtoken;\
  631.     yystate = *yyps;\
  632.     yylval = newvalue;\
  633.     goto yynewstate;\
  634. }
  635. #define YYRECOVERING()    (!!yyerrflag)
  636. #ifndef YYDEBUG
  637. #    define YYDEBUG    1    /* make debugging available */
  638. #endif
  639.  
  640. /*
  641. ** user known globals
  642. */
  643. int yydebug;            /* set to 1 to get debugging */
  644.  
  645. /*
  646. ** driver internal defines
  647. */
  648. #define YYFLAG        (-1000)
  649.  
  650. /*
  651. ** global variables used by the parser
  652. */
  653. YYSTYPE yyv[ YYMAXDEPTH ];    /* value stack */
  654. int yys[ YYMAXDEPTH ];        /* state stack */
  655.  
  656. YYSTYPE *yypv;            /* top of value stack */
  657. int *yyps;            /* top of state stack */
  658.  
  659. int yystate;            /* current state */
  660. int yytmp;            /* extra var (lasts between blocks) */
  661.  
  662. int yynerrs;            /* number of errors */
  663. int yyerrflag;            /* error recovery flag */
  664. int yychar;            /* current input token number */
  665.  
  666.  
  667.  
  668. /*
  669. ** yyparse - return 0 if worked, 1 if syntax error not recovered from
  670. */
  671. int
  672. yyparse()
  673. {
  674.     register YYSTYPE *yypvt;    /* top of value stack for $vars */
  675.  
  676.     /*
  677.     ** Initialize externals - yyparse may be called more than once
  678.     */
  679.     yypv = &yyv[-1];
  680.     yyps = &yys[-1];
  681.     yystate = 0;
  682.     yytmp = 0;
  683.     yynerrs = 0;
  684.     yyerrflag = 0;
  685.     yychar = -1;
  686.  
  687.     goto yystack;
  688.     {
  689.         register YYSTYPE *yy_pv;    /* top of value stack */
  690.         register int *yy_ps;        /* top of state stack */
  691.         register int yy_state;        /* current state */
  692.         register int  yy_n;        /* internal state number info */
  693.  
  694.         /*
  695.         ** get globals into registers.
  696.         ** branch to here only if YYBACKUP was called.
  697.         */
  698.     yynewstate:
  699.         yy_pv = yypv;
  700.         yy_ps = yyps;
  701.         yy_state = yystate;
  702.         goto yy_newstate;
  703.  
  704.         /*
  705.         ** get globals into registers.
  706.         ** either we just started, or we just finished a reduction
  707.         */
  708.     yystack:
  709.         yy_pv = yypv;
  710.         yy_ps = yyps;
  711.         yy_state = yystate;
  712.  
  713.         /*
  714.         ** top of for (;;) loop while no reductions done
  715.         */
  716.     yy_stack:
  717.         /*
  718.         ** put a state and value onto the stacks
  719.         */
  720. #if YYDEBUG
  721.         /*
  722.         ** if debugging, look up token value in list of value vs.
  723.         ** name pairs.  0 and negative (-1) are special values.
  724.         ** Note: linear search is used since time is not a real
  725.         ** consideration while debugging.
  726.         */
  727.         if ( yydebug )
  728.         {
  729.             register int yy_i;
  730.  
  731.             printf( "State %d, token ", yy_state );
  732.             if ( yychar == 0 )
  733.                 printf( "end-of-file\n" );
  734.             else if ( yychar < 0 )
  735.                 printf( "-none-\n" );
  736.             else
  737.             {
  738.                 for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
  739.                     yy_i++ )
  740.                 {
  741.                     if ( yytoks[yy_i].t_val == yychar )
  742.                         break;
  743.                 }
  744.                 printf( "%s\n", yytoks[yy_i].t_name );
  745.             }
  746.         }
  747. #endif /* YYDEBUG */
  748.         if ( ++yy_ps >= &yys[ YYMAXDEPTH ] )    /* room on stack? */
  749.         {
  750.             yyerror( "yacc stack overflow" );
  751.             YYABORT;
  752.         }
  753.         *yy_ps = yy_state;
  754.         *++yy_pv = yyval;
  755.  
  756.         /*
  757.         ** we have a new state - find out what to do
  758.         */
  759.     yy_newstate:
  760.         if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG )
  761.             goto yydefault;        /* simple state */
  762. #if YYDEBUG
  763.         /*
  764.         ** if debugging, need to mark whether new token grabbed
  765.         */
  766.         yytmp = yychar < 0;
  767. #endif
  768.         if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  769.             yychar = 0;        /* reached EOF */
  770. #if YYDEBUG
  771.         if ( yydebug && yytmp )
  772.         {
  773.             register int yy_i;
  774.  
  775.             printf( "Received token " );
  776.             if ( yychar == 0 )
  777.                 printf( "end-of-file\n" );
  778.             else if ( yychar < 0 )
  779.                 printf( "-none-\n" );
  780.             else
  781.             {
  782.                 for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
  783.                     yy_i++ )
  784.                 {
  785.                     if ( yytoks[yy_i].t_val == yychar )
  786.                         break;
  787.                 }
  788.                 printf( "%s\n", yytoks[yy_i].t_name );
  789.             }
  790.         }
  791. #endif /* YYDEBUG */
  792.         if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) )
  793.             goto yydefault;
  794.         if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar )    /*valid shift*/
  795.         {
  796.             yychar = -1;
  797.             yyval = yylval;
  798.             yy_state = yy_n;
  799.             if ( yyerrflag > 0 )
  800.                 yyerrflag--;
  801.             goto yy_stack;
  802.         }
  803.  
  804.     yydefault:
  805.         if ( ( yy_n = yydef[ yy_state ] ) == -2 )
  806.         {
  807. #if YYDEBUG
  808.             yytmp = yychar < 0;
  809. #endif
  810.             if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  811.                 yychar = 0;        /* reached EOF */
  812. #if YYDEBUG
  813.             if ( yydebug && yytmp )
  814.             {
  815.                 register int yy_i;
  816.  
  817.                 printf( "Received token " );
  818.                 if ( yychar == 0 )
  819.                     printf( "end-of-file\n" );
  820.                 else if ( yychar < 0 )
  821.                     printf( "-none-\n" );
  822.                 else
  823.                 {
  824.                     for ( yy_i = 0;
  825.                         yytoks[yy_i].t_val >= 0;
  826.                         yy_i++ )
  827.                     {
  828.                         if ( yytoks[yy_i].t_val
  829.                             == yychar )
  830.                         {
  831.                             break;
  832.                         }
  833.                     }
  834.                     printf( "%s\n", yytoks[yy_i].t_name );
  835.                 }
  836.             }
  837. #endif /* YYDEBUG */
  838.             /*
  839.             ** look through exception table
  840.             */
  841.             {
  842.                 register int *yyxi = yyexca;
  843.  
  844.                 while ( ( *yyxi != -1 ) ||
  845.                     ( yyxi[1] != yy_state ) )
  846.                 {
  847.                     yyxi += 2;
  848.                 }
  849.                 while ( ( *(yyxi += 2) >= 0 ) &&
  850.                     ( *yyxi != yychar ) )
  851.                     ;
  852.                 if ( ( yy_n = yyxi[1] ) < 0 )
  853.                     YYACCEPT;
  854.             }
  855.         }
  856.  
  857.         /*
  858.         ** check for syntax error
  859.         */
  860.         if ( yy_n == 0 )    /* have an error */
  861.         {
  862.             /* no worry about speed here! */
  863.             switch ( yyerrflag )
  864.             {
  865.             case 0:        /* new error */
  866.                 yyerror( "syntax error" );
  867.                 goto skip_init;
  868.             yyerrlab:
  869.                 /*
  870.                 ** get globals into registers.
  871.                 ** we have a user generated syntax type error
  872.                 */
  873.                 yy_pv = yypv;
  874.                 yy_ps = yyps;
  875.                 yy_state = yystate;
  876.                 yynerrs++;
  877.             skip_init:
  878.             case 1:
  879.             case 2:        /* incompletely recovered error */
  880.                     /* try again... */
  881.                 yyerrflag = 3;
  882.                 /*
  883.                 ** find state where "error" is a legal
  884.                 ** shift action
  885.                 */
  886.                 while ( yy_ps >= yys )
  887.                 {
  888.                     yy_n = yypact[ *yy_ps ] + YYERRCODE;
  889.                     if ( yy_n >= 0 && yy_n < YYLAST &&
  890.                         yychk[yyact[yy_n]] == YYERRCODE)                    {
  891.                         /*
  892.                         ** simulate shift of "error"
  893.                         */
  894.                         yy_state = yyact[ yy_n ];
  895.                         goto yy_stack;
  896.                     }
  897.                     /*
  898.                     ** current state has no shift on
  899.                     ** "error", pop stack
  900.                     */
  901. #if YYDEBUG
  902. #    define _POP_ "Error recovery pops state %d, uncovers state %d\n"
  903.                     if ( yydebug )
  904.                         printf( _POP_, *yy_ps,
  905.                             yy_ps[-1] );
  906. #    undef _POP_
  907. #endif
  908.                     yy_ps--;
  909.                     yy_pv--;
  910.                 }
  911.                 /*
  912.                 ** there is no state on stack with "error" as
  913.                 ** a valid shift.  give up.
  914.                 */
  915.                 YYABORT;
  916.             case 3:        /* no shift yet; eat a token */
  917. #if YYDEBUG
  918.                 /*
  919.                 ** if debugging, look up token in list of
  920.                 ** pairs.  0 and negative shouldn't occur,
  921.                 ** but since timing doesn't matter when
  922.                 ** debugging, it doesn't hurt to leave the
  923.                 ** tests here.
  924.                 */
  925.                 if ( yydebug )
  926.                 {
  927.                     register int yy_i;
  928.  
  929.                     printf( "Error recovery discards " );
  930.                     if ( yychar == 0 )
  931.                         printf( "token end-of-file\n" );
  932.                     else if ( yychar < 0 )
  933.                         printf( "token -none-\n" );
  934.                     else
  935.                     {
  936.                         for ( yy_i = 0;
  937.                             yytoks[yy_i].t_val >= 0;
  938.                             yy_i++ )
  939.                         {
  940.                             if ( yytoks[yy_i].t_val
  941.                                 == yychar )
  942.                             {
  943.                                 break;
  944.                             }
  945.                         }
  946.                         printf( "token %s\n",
  947.                             yytoks[yy_i].t_name );
  948.                     }
  949.                 }
  950. #endif /* YYDEBUG */
  951.                 if ( yychar == 0 )    /* reached EOF. quit */
  952.                     YYABORT;
  953.                 yychar = -1;
  954.                 goto yy_newstate;
  955.             }
  956.         }/* end if ( yy_n == 0 ) */
  957.         /*
  958.         ** reduction by production yy_n
  959.         ** put stack tops, etc. so things right after switch
  960.         */
  961. #if YYDEBUG
  962.         /*
  963.         ** if debugging, print the string that is the user's
  964.         ** specification of the reduction which is just about
  965.         ** to be done.
  966.         */
  967.         if ( yydebug )
  968.             printf( "Reduce by (%d) \"%s\"\n",
  969.                 yy_n, yyreds[ yy_n ] );
  970. #endif
  971.         yytmp = yy_n;            /* value to switch over */
  972.         yypvt = yy_pv;            /* $vars top of value stack */
  973.         /*
  974.         ** Look in goto table for next state
  975.         ** Sorry about using yy_state here as temporary
  976.         ** register variable, but why not, if it works...
  977.         ** If yyr2[ yy_n ] doesn't have the low order bit
  978.         ** set, then there is no action to be done for
  979.         ** this reduction.  So, no saving & unsaving of
  980.         ** registers done.  The only difference between the
  981.         ** code just after the if and the body of the if is
  982.         ** the goto yy_stack in the body.  This way the test
  983.         ** can be made before the choice of what to do is needed.
  984.         */
  985.         {
  986.             /* length of production doubled with extra bit */
  987.             register int yy_len = yyr2[ yy_n ];
  988.  
  989.             if ( !( yy_len & 01 ) )
  990.             {
  991.                 yy_len >>= 1;
  992.                 yyval = ( yy_pv -= yy_len )[1];    /* $$ = $1 */
  993.                 yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  994.                     *( yy_ps -= yy_len ) + 1;
  995.                 if ( yy_state >= YYLAST ||
  996.                     yychk[ yy_state =
  997.                     yyact[ yy_state ] ] != -yy_n )
  998.                 {
  999.                     yy_state = yyact[ yypgo[ yy_n ] ];
  1000.                 }
  1001.                 goto yy_stack;
  1002.             }
  1003.             yy_len >>= 1;
  1004.             yyval = ( yy_pv -= yy_len )[1];    /* $$ = $1 */
  1005.             yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  1006.                 *( yy_ps -= yy_len ) + 1;
  1007.             if ( yy_state >= YYLAST ||
  1008.                 yychk[ yy_state = yyact[ yy_state ] ] != -yy_n )
  1009.             {
  1010.                 yy_state = yyact[ yypgo[ yy_n ] ];
  1011.             }
  1012.         }
  1013.                     /* save until reenter driver code */
  1014.         yystate = yy_state;
  1015.         yyps = yy_ps;
  1016.         yypv = yy_pv;
  1017.     }
  1018.     /*
  1019.     ** code supplied by user is placed in this switch
  1020.     */
  1021.     switch( yytmp )
  1022.     {
  1023.         
  1024. case 3:
  1025. # line 35 "getdate.y"
  1026.  
  1027.         {timeflag++;} break;
  1028. case 4:
  1029. # line 37 "getdate.y"
  1030.  
  1031.         {zoneflag++;} break;
  1032. case 5:
  1033. # line 39 "getdate.y"
  1034.  
  1035.         {dateflag++;} break;
  1036. case 6:
  1037. # line 41 "getdate.y"
  1038.  
  1039.         {dayflag++;} break;
  1040. case 7:
  1041. # line 43 "getdate.y"
  1042.  
  1043.         {relflag++;} break;
  1044. case 9:
  1045. # line 47 "getdate.y"
  1046.  
  1047.         {if (timeflag && dateflag && !relflag) year = yypvt[-0];
  1048.         else {timeflag++;hh = yypvt[-0]/100;mm = yypvt[-0]%100;ss = 0;merid = 24;}} break;
  1049. case 10:
  1050. # line 51 "getdate.y"
  1051.  
  1052.         {hh = yypvt[-1]; mm = 0; ss = 0; merid = yypvt[-0];} break;
  1053. case 11:
  1054. # line 53 "getdate.y"
  1055.  
  1056.         {hh = yypvt[-2]; mm = yypvt[-0]; merid = 24;} break;
  1057. case 12:
  1058. # line 55 "getdate.y"
  1059.  
  1060.         {hh = yypvt[-3]; mm = yypvt[-1]; merid = yypvt[-0];} break;
  1061. case 13:
  1062. # line 57 "getdate.y"
  1063.  
  1064.         {hh = yypvt[-3]; mm = yypvt[-1]; merid = 24;
  1065.         daylight = STANDARD; ourzone = yypvt[-0]%100 + 60*yypvt[-0]/100;} break;
  1066. case 14:
  1067. # line 60 "getdate.y"
  1068.  
  1069.         {hh = yypvt[-4]; mm = yypvt[-2]; ss = yypvt[-0]; merid = 24;} break;
  1070. case 15:
  1071. # line 62 "getdate.y"
  1072.  
  1073.         {hh = yypvt[-5]; mm = yypvt[-3]; ss = yypvt[-1]; merid = yypvt[-0];} break;
  1074. case 16:
  1075. # line 64 "getdate.y"
  1076.  
  1077.         {hh = yypvt[-5]; mm = yypvt[-3]; ss = yypvt[-1]; merid = 24;
  1078.         daylight = STANDARD; ourzone = yypvt[-0]%100 + 60*yypvt[-0]/100;} break;
  1079. case 17:
  1080. # line 68 "getdate.y"
  1081.  
  1082.         {ourzone = yypvt[-0]; daylight = STANDARD;} break;
  1083. case 18:
  1084. # line 70 "getdate.y"
  1085.  
  1086.         {ourzone = yypvt[-0]; daylight = DAYLIGHT;} break;
  1087. case 19:
  1088. # line 73 "getdate.y"
  1089.  
  1090.         {dayord = 1; dayreq = yypvt[-0];} break;
  1091. case 20:
  1092. # line 75 "getdate.y"
  1093.  
  1094.         {dayord = 1; dayreq = yypvt[-1];} break;
  1095. case 21:
  1096. # line 77 "getdate.y"
  1097.  
  1098.         {dayord = yypvt[-1]; dayreq = yypvt[-0];} break;
  1099. case 22:
  1100. # line 80 "getdate.y"
  1101.  
  1102.         {month = yypvt[-2]; day = yypvt[-0];} break;
  1103. case 23:
  1104. # line 82 "getdate.y"
  1105.  
  1106.         {month = yypvt[-4]; day = yypvt[-2]; year = yypvt[-0];} break;
  1107. case 24:
  1108. # line 84 "getdate.y"
  1109.  
  1110.         {month = yypvt[-1]; day = yypvt[-0];} break;
  1111. case 25:
  1112. # line 86 "getdate.y"
  1113.  
  1114.         {month = yypvt[-3]; day = yypvt[-2]; year = yypvt[-0];} break;
  1115. case 26:
  1116. # line 88 "getdate.y"
  1117.  
  1118.         {month = yypvt[-0]; day = yypvt[-1];} break;
  1119. case 27:
  1120. # line 90 "getdate.y"
  1121.  
  1122.         {month = yypvt[-1]; day = yypvt[-2]; year = yypvt[-0];} break;
  1123. case 28:
  1124. # line 94 "getdate.y"
  1125.  
  1126.         {relsec +=  60L * yypvt[-1] * yypvt[-0];} break;
  1127. case 29:
  1128. # line 96 "getdate.y"
  1129.  
  1130.         {relmonth += yypvt[-1] * yypvt[-0];} break;
  1131. case 30:
  1132. # line 98 "getdate.y"
  1133.  
  1134.         {relsec += yypvt[-1];} break;
  1135. case 31:
  1136. # line 100 "getdate.y"
  1137.  
  1138.         {relsec +=  60L * yypvt[-0];} break;
  1139. case 32:
  1140. # line 102 "getdate.y"
  1141.  
  1142.         {relmonth += yypvt[-0];} break;
  1143. case 33:
  1144. # line 104 "getdate.y"
  1145.  
  1146.         {relsec++;} break;
  1147. case 34:
  1148. # line 106 "getdate.y"
  1149.  
  1150.         {relsec = -relsec; relmonth = -relmonth;} break;
  1151.     }
  1152.     goto yystack;        /* reset registers in driver code */
  1153. }
  1154.